package com.wl.system.controller;

import com.wl.basic.util.AjaxResult;
import com.wl.system.service.ISystemdictionarytypeService;
import com.wl.system.domain.Systemdictionarytype;
import com.wl.system.query.SystemdictionarytypeQuery;
import com.wl.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
* 后端接口类；
*/
@RestController
@RequestMapping("/systemdictionarytype")
public class SystemdictionarytypeController {

    @Autowired
    public ISystemdictionarytypeService systemdictionarytypeService;

    /**
     * 接口：添加或修改
     * @param systemdictionarytype  传递的实体
     * @return AjaxResult 响应给前端
     */
    @PutMapping
    public AjaxResult addAanUpt(@RequestBody Systemdictionarytype systemdictionarytype){
        try {
            if( systemdictionarytype.getId()!=null)
                systemdictionarytypeService.update(systemdictionarytype);
            else
                systemdictionarytypeService.save(systemdictionarytype);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }

    /**
    * 接口：删除
    * @param id
    * @return AjaxResult 响应给前端
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult deleteById(@PathVariable("id") Long id){
        try {
            systemdictionarytypeService.remove(id);
            return new AjaxResult();
        } catch (Exception e) {
        e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }
    }

    /**
    * 接口：批量删除
    * @param ids
    * @return AjaxResult 响应给前端
    */
    @PatchMapping
    public AjaxResult removeA(@RequestBody List<Long> ids){
        try {
                systemdictionarytypeService.removeA(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"批量删除失败");
        }
    }

    /**
    * 接口：查询单个对象
    * @param id
    */
    @GetMapping("/{id}")
    public Systemdictionarytype findById(@PathVariable("id")Long id) {
        return systemdictionarytypeService.loadById(id);
    }


    /**
    * 接口：查询所有
    * @return
    */
    @GetMapping
    public List<Systemdictionarytype> findAll(){
        return systemdictionarytypeService.loadAll();
    }


   /**
    * 接口：分页查询或高级查询
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping
    public PageList<Systemdictionarytype> queryPage(@RequestBody SystemdictionarytypeQuery query) {
        return systemdictionarytypeService.queryPage(query);
    }
}
